package com.vincent.music;

import java.util.Stack;

public class Main {
    public static void main(String[] args) {
//        String expression = "(())";
        String expression = "((1+2*2+2-1+3*(1+2))*(2+(1+(1E4-1+3)*8+1+3-2/1+2/(1+5)+1)*5-2*10/2+(1+2)))";
        System.out.println(expression.length());
        int leftIndex = 1; // 找到第一个左括号的位置
        int rightIndex = findMatchingRight(expression, leftIndex);
        System.out.println("Left parenthesis at index: " + leftIndex);
        System.out.println("Matching right parenthesis at index: " + rightIndex);
    }

    public static int findMatchingRight(String expression, int leftIndex) {
        Stack<Integer> stack = new Stack<>();
        for (int i = leftIndex; i < expression.length(); i++) {
            char c = expression.charAt(i);
            if (c == '(') {
                stack.push(i);
            } else if (c == ')') {
                stack.pop();
                if (stack.isEmpty()) {
                    return i;
                }
            }
            System.out.println("得到的");
        }
        return -1; // 如果没有匹配的右括号，返回-1或者其他合适的值
    }
}
